import { _decorator, CCBoolean, CCFloat, CCInteger, CircleCollider2D, Collider2D, Component, Contact2DType, IPhysics2DContact, Node, tween, Vec2, Vec3 } from 'cc';
import { Enemy } from '../../Actor/Enemy/Enemy';
const { ccclass, property } = _decorator;

@ccclass('BlackHole_Skill_Controller')
export class BlackHole_Skill_Controller extends Component {
    @property(CCFloat)public maxSize:number;
    @property(CCFloat)public growSpeed:number;
    @property(CCBoolean)public canGrow:boolean;

    public targets:Array<Enemy> = new Array<Enemy>();

    protected start(): void {
        this.getComponent(CircleCollider2D).on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
    }

    protected update(dt: number): void {
        if(this.canGrow){
            // let sca:Vec3;
            //Vec3.lerp(this.node.scale, this.node.scale, new Vec3(this.maxSize, this.maxSize, 0), this.growSpeed*dt);
            //this.node.setScale(sca);
            tween(this.node)
            .to(this.growSpeed, {scale: new Vec3(this.maxSize, this.maxSize, this.maxSize)},{easing:"quadOut"})
            .start()
        }
    }

    private onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null){
        
        if(otherCollider.node.getComponent(Enemy))
            this.targets.push(otherCollider.node.getComponent(Enemy)); 
        console.info(this.targets);
    }
    
}


